package com.knowif.backend.service;

import com.github.pagehelper.PageHelper;
import com.knowif.pojo.OfferInterviewThanksCollection;
import com.knowif.pojo.OfferInterviewThanksCollectionExample;
import com.knowif.service.OfferInterviewThanksCollection_service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ：Xh
 * @date ：Created in 2019/6/5 0005 20:58
 */
@Service
public class OfferInterviewThanksCollectionService {

    @Autowired
    private OfferInterviewThanksCollection_service offerInterviewThanksCollection_service;

    /**
     * 条件查询offerInterviewThanksCollection
     * @param offerInterviewThanksCollectionExample
     * @return
     */
    public List<OfferInterviewThanksCollection> selectOfferInterviewThanksCollection(OfferInterviewThanksCollectionExample offerInterviewThanksCollectionExample){
        return offerInterviewThanksCollection_service.selectOfferInterviewThanksCollection(offerInterviewThanksCollectionExample);
    }

    /**
     * 条件查询offerInterviewThanksCollection
     * @param offerInterviewThanksCollectionExample
     * @param pageable 是否需要分页
     * @return
     */
    public List<OfferInterviewThanksCollection> selectOfferInterviewThanksCollection(OfferInterviewThanksCollectionExample offerInterviewThanksCollectionExample, boolean pageable){
        if(! pageable){
            PageHelper.clearPage();
        }
        return offerInterviewThanksCollection_service.selectOfferInterviewThanksCollection(offerInterviewThanksCollectionExample);
    }

    /**
     * 保存offerInterviewThanksCollection
     * @return
     */
    public boolean saveOfferInterviewThanksCollection(OfferInterviewThanksCollection offerInterviewThanksCollection){
        int i = offerInterviewThanksCollection_service.saveOfferInterviewThanksCollection(offerInterviewThanksCollection);
        if(i == 0){
            return false;
        }
        return true;
    }

    /**
     * 保存offerInterviewThanksCollection
     * @return
     */
    public boolean updateOfferInterviewThanksCollectionNotNull(OfferInterviewThanksCollection offerInterviewThanksCollection){
        int i = offerInterviewThanksCollection_service.updateOfferInterviewThanksCollectionNotNull(offerInterviewThanksCollection);
        if(i == 0){
            return false;
        }
        return true;
    }

    /**
     * 保存offerInterviewThanksCollection
     * @return
     */
    public boolean updateOfferInterviewThanksCollection(OfferInterviewThanksCollection offerInterviewThanksCollection){
        int i = offerInterviewThanksCollection_service.updateOfferInterviewThanksCollection(offerInterviewThanksCollection);
        if(i == 0){
            return false;
        }
        return true;
    }

    /**
     * 删除offerInterviewThanksCollection
     * @return
     */
    public boolean deleteOfferInterviewThanksCollection(int offerInterviewThanksCollectionId){
        int i = offerInterviewThanksCollection_service.deleteOfferInterviewThanksCollection(offerInterviewThanksCollectionId);
        if(i == 0){
            return false;
        }
        return true;
    }

    /**
     * 取消收藏or感谢
     * @param offerInterviewThanksCollection
     */
    public void cancle(OfferInterviewThanksCollection offerInterviewThanksCollection) {
        OfferInterviewThanksCollectionExample thanksCollectionExample = new OfferInterviewThanksCollectionExample();
        thanksCollectionExample.createCriteria().andUserIdEqualTo(offerInterviewThanksCollection.getUserId())
                .andThanksCollectionTypeEqualTo(offerInterviewThanksCollection.getThanksCollectionType())
                .andCollectionTypeEqualTo(offerInterviewThanksCollection.getCollectionType())
                .andOfferInterviewIdEqualTo(offerInterviewThanksCollection.getOfferInterviewId());
        offerInterviewThanksCollection_service.deleteOfferInterviewThanksCollectionByParams(thanksCollectionExample);
    }
}
